const { DataTypes } = require('sequelize')

const sequelize = require('../db/sequelize')

const Goods = require('../model/goods.model')

const Cart = sequelize.define("nk_cart", {
    // id 自动创建
    goods_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '商品ID'
    },
    user_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '用户ID'
    },
    number: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 1,
        comment: '数量'
    },
    selected: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: true,
        comment: '是否选中'
    }
}, {
    timestamps: true,//时间戳字段
    // paranoid: true,
},)

// 强制 删除并创建表
// Cart.sync({ focus: true })

// 关联 外键关联 模型之间的关系 外键
Cart.belongsTo(Goods,{
    foreignKey:'goods_id',
    as:'goods_info'
})

module.exports = Cart